#ifndef SerialHelper_Hpp
#define SerialHelper_Hpp

#include <boost/asio.hpp>
//#include <boost/bind.hpp>
//#include <boost/array.hpp>
#include <boost/asio/steady_timer.hpp>
#include <memory>
#include <thread>
#include <functional>
#include <queue>
#include <string.h>
#include <vector>
using namespace boost::asio;
struct SerialConfig
{
    std::string port;
    int baud;
};

class Serial
{
public:
    Serial(SerialConfig config);
    Serial(std::string port,int baud);
    ~Serial();

    void open();
   
    void close();
   // void write(std::string &buf);
    void write(std::vector<u_char> &buf);
    void write(std::string &buf);
    void runThreadFunc();
   int rec_flag;
   std::string recv_msg_;
   std::vector<u_char> serial_rec_v8;
   std::vector<u_int8_t> sendbuf_vect;
   virtual void recvMsg(std::vector<u_int8_t>& msg) = 0;
   void stopTimer(); 
   virtual void startTimer(int ms_s);
   void display_rec_hex(std::vector<u_int8_t>& msg);
   std::string toHex(uint8_t ch);
      ///timer
    std::chrono::milliseconds interval; // 定时间隔
    bool running;                          // 运行标志
    ///timer end
private:
    void read();
    char receiveData[256];
     std::vector<u_int8_t> msg_buf_;

private:
    boost::system::error_code ec_;
    io_service io_;
    std::shared_ptr<serial_port> serial_port_;
     std::thread read_thread_;
   SerialConfig config_;
    boost::asio::steady_timer status_timer_;
    bool is_connected;

    

   
};



#endif
